<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Template{


function Template(){
	
	
	}
	
	public function viewForm($content=NULL){
		$this->templateForm($content);
	}
	public function viewOnlyForm($content=NULL){
		$this->templateOnlyForm($content);
	}
	public function viewPrint($content=NULL){
		$this->templatePrint($content);
	}
	
	public function viewTable($propContenedor=NULL,$content=NULL){
		$this->templateTable($propContenedor,$content);
	}
	
	public function viewMultiTable($propContenedor=NULL,$content=NULL){
		$this->templateMultiTable($propContenedor,$content);
	}

	public function viewFormTable($propContenedor=NULL,$content=NULL){
		$this->templateFormTable($content,$nameTabla,$tamanho);
	}

	public function viewFormTableForm($propContenedor=NULL,$content=NULL){
		$this->templateFormTableForm($content,$nameTabla,$tamanho);
	}

private function createTable($content,$num=''){
	$CI =& get_instance();
	$CI->load->library('dbconfiguration');
			$plantilla = array (
                    'table_open'          => '<table id="dataTable'.$num.'" class="table table-bordered table-condensed table-hover table-striped">',

                    'heading_row_start'   => '<tr>',
                    'heading_row_end'     => '</tr>',
                    'heading_cell_start'  => '<th>',
                    'heading_cell_end'    => '</th>',

                    'row_start'           => '<tr>',
                    'row_end'             => '</tr>',
                    'cell_start'          => '<td>',
                    'cell_end'            => '</td>',

                    'row_alt_start'       => '<tr>',
                    'row_alt_end'         => '</tr>',
                    'cell_alt_start'      => '<td>',
                    'cell_alt_end'        => '</td>',

                    'table_close'         => '</table>'
              );
			
			$CI->table->set_template($plantilla);
			$CI->table->set_heading($CI->dbconfiguration->stringComaToArrayReplaceHead($content['head']));
			
			for($i=0;$i<count($content['rows']);$i++){

			$CI->table->add_row($CI->service->stringComaToArrayReplaceHead($content['rows'][$i]));
			}
			return $CI->table;
	
	}
private function templateForm($content=NULL){
	
			$CI =& get_instance();
			
			$content=$this->datosUser($content);
			
			$template["head"]=$CI->load->view('includes/head',$content,true);
			$template["top"]=$CI->load->view('includes/top',$content,true);
			$template["menu"]=$CI->load->view('includes/menu',$content,true);
			$template["content"]=$CI->load->view('includes/content2',$content,true);
			$template["footer"]=$CI->load->view('includes/footer',$content,true);
			$template["helpModal"]=$CI->load->view('includes/help-modal',$content,true);
			$template["javascript"]=$CI->load->view('includes/javascript',$content,true);
			$CI->load->view('template',$template);
		}
private function templateOnlyForm($content=NULL){
			$CI =& get_instance();
			
			$content=$this->datosUser($content);
		
			$template["head"]=$CI->load->view('includes/head',$content,true);
			$template["top"]="";
			$template["menu"]="";
			$template["content"]=$CI->load->view('includes/content2',$content,true); 
			$template["footer"]=$CI->load->view('includes/footer',$content,true);
			$template["helpModal"]=$CI->load->view('includes/help-modal',$content,true);
			$template["javascript"]=$CI->load->view('includes/javascript',$content,true);
			$CI->load->view('template',$template);
		}
private function templatePrint($content=NULL){
			$CI =& get_instance();
			
			$content=$this->datosUser($content);
			
			$template["head"]="";
			$template["top"]="";
			$template["menu"]="";
			$template["content"]=$CI->load->view('includes/content3',$content,true);
			$template["footer"]="";
			$template["helpModal"]="";
			$template["javascript"]="";
			$CI->load->view('template',$template);
		}
		
private function templateFormTable($propContenedor=NULL,$content=NULL){
			$CI =& get_instance();
			
			$content=$this->datosUser($content);
		
			$template["head"]=$CI->load->view('includes/head',$content,true);
			$template["top"]=$CI->load->view('includes/top',$content,true);
			$template["menu"]=$CI->load->view('includes/menu',$content,true);
			
			
			#table#
			
			$tabla=$this->createTable($content);
			$content['contenido2']=$this->createContenedor($propContenedor,$tabla->generate());
			
			##end table##
			
			$template["content"]=$CI->load->view('includes/content2',$content,true);
			
			
			
			$template["footer"]=$CI->load->view('includes/footer',$content,true);
			$template["helpModal"]=$CI->load->view('includes/help-modal',$content,true);
			$template["javascript"]=$CI->load->view('includes/javascript',$content,true);
			$CI->load->view('template',$template);
		}
		
		
private function templateFormTableForm($propContenedor=NULL,$content=NULL){
			$CI =& get_instance();
			
			$content=$this->datosUser($content);
			
			$template["head"]=$CI->load->view('includes/head',$content,true);
			$template["top"]=$CI->load->view('includes/top',$content,true);
			$template["menu"]=$CI->load->view('includes/menu',$content,true);
			
			
			#table#
			
			$tabla=$this->createTable($content);
			$content['contenido2']=$this->createContenedor($propContenedor,$tabla->generate());
			
			##end table##
			
			$template["content"]=$CI->load->view('includes/content2',$content,true);
			
			
			
			$template["footer"]=$CI->load->view('includes/footer',$content,true);
			$template["helpModal"]=$CI->load->view('includes/help-modal',$content,true);
			$template["javascript"]=$CI->load->view('includes/javascript',$content,true);
			$CI->load->view('template',$template);
		}

private function templateTable($propContenedor=NULL,$content=NULL){
			$CI =& get_instance();
			
			if(!isset($content['tituloHtml'])) $content['tituloHtml']='';
		
		
			$tabla=$this->createTable($content);
			$content['contenido']=$this->createContenedor($propContenedor,$tabla->generate());
			
			
			$template["head"]=$CI->load->view('template/html/includes/head',$content,true);
			$template["top"]=$CI->load->view('template/html/includes/top',$content,true);
			
			//agregamos la tabla
			$template["contenido"]=$CI->load->view('template/html/includes/tabla',$content,true);
			$template["javascript"]=$CI->load->view('template/html/includes/javascript',$content,true);
			$CI->load->view('template/html/theme',$template);
		}
private function templateMultiTable($propContendor=NULL,$content=NULL){
			$CI =& get_instance();
			
			
			$content=$this->datosUser($content);
			$content['contenido']='';
			for($i=0;$i<count($content['rows']);$i++){
				$cont['rows']=$content['rows'][$i];
				$cont['head']=$content['head'][$i];
				$num='';
				if($i==0) $num=''; else $num=$i;
				$tabla=$this->createTable($cont,$num);
				
				$content['contenido'].=$this->createContenedor($propContendor,$tabla->generate());
			}
			
			$template["head"]=$CI->load->view('includes/head',$content,true);
			$template["top"]=$CI->load->view('includes/top',$content,true);
			$template["menu"]=$CI->load->view('includes/menu',$content,true);
			//agregamos la tabla
			//$content["contenido"]=$CI->load->view('includes/tabla',$content,true);
			$template["content"]=$CI->load->view('includes/content2',$content,true);
			$template["footer"]=$CI->load->view('includes/footer',$content,true);
			$template["helpModal"]=$CI->load->view('includes/help-modal',$content,true);
			$template["javascript"]=$CI->load->view('includes/javascript',$content,true);
			$CI->load->view('template',$template);
		}
		
function createContenedor($propContenedor,$contenido){
	
	
	if($propContenedor['botones']!='')
	$cadenaBtn='<div align="right">'.$propContenedor['botones'].'&nbsp;&nbsp;</div>';
	else
	$cadenaBtn='';
	
	$tituloHtml='';
	 
	if($propContenedor['tituloHtml']!='')
	$tituloHtml='<h3 style="padding-left:20px">'.$propContenedor['tituloHtml'].'</h3>';
	else
	$tituloHtml='';
	
	$cadena=$tituloHtml.'<div class="col-lg-'.$propContenedor['tamanho'].'">
	<div class="box">
 <header>
  <h5>'.$propContenedor['nameTabla'].'</h5>'.$cadenaBtn.'
 </header>
 <div class="body">'.$contenido.'</div>
</div>
</div>';
				return $cadena;
	
	}
	
function createContenedor2($nameForm,$contenido,$nameForm2,$contenido2,$tamanho=12){
	$cadena='<div class="col-lg-'.$tamanho.'">
	<div class="box">
 <header>
  <h5>'.$nameForm.'</h5>
 </header>
 <div class="body">'.$contenido.'</div>
</div>
<div class="box">
 <header>
  <h5>'.$nameForm2.'</h5>
 </header>
 <div class="body">'.$contenido2.'</div>
</div>
</div>';
				return $cadena;
	
	}
	
	
	private function datosUser($content){
		/*
		$CI =& get_instance();
		$CI->load->library('session');
			$CI->load->library('serviceasociado');
			$usuario=$CI->session->userdata('usuario');
			$content['perfil']=$usuario['perfil'];
			$content['nombrex']=$usuario['name'];
			if($content['perfil']==5){
			$idx=$usuario['id'];
			$id0=$CI->serviceasociado->dataAsociadoUser($idx);			
			$id=$id0[0]['idasociado'];
			$datosAsociado=$CI->serviceasociado->data($id);
			if(isset($datosAsociado[0]['imagen']) && $datosAsociado[0]['imagen']!='')
			$content['imagen']=$content['url'].'upload/asociado/'.$datosAsociado[0]['imagen'];
			else
			$content['imagen']=$content['url'].'assets/img/user.gif';
			}else{
				$content['imagen']=$content['url'].'assets/img/user.gif';
				}
			return $content;*/
		}
	
}

?>